<template>
  <div class="info">
    <el-table :data=commentList style="width: 100%" border >
      <el-table-column label="编号" prop="commentId"  align="center" width="50px"/>
      <el-table-column label="电影名称" prop="movieName"  align="center" />
      <el-table-column label="评论人" prop="vipName"  align="center" />
      <el-table-column label="评分" prop="score"  align="center" />
      <el-table-column label="评论内容" prop="content" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作"  align="center" width="150px">
        <template slot-scope="scope">
          <el-button type="danger" size="small" @click="delInfo(scope.row.commentId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination layout="total,prev,pager,next,sizes,jumper"
                   :total='pageInfo.totalPage'
                   :page-size='pageInfo.pageSize'
                   :current-page='pageInfo.currPage'
                   :page-sizes=[5,10,20,30,50,100]
                   @size-change="sizeChange"
                   @current-change="currentChange"
    />
  </div>
</template>

<script>

export default {
  name: 'FilmReview',
  data () {
    return {
      commentList: [],
      searchInfo: {
        movieId: '',
        page: 1,
        limit: 5
      },
      pageInfo: {
      }
    }
  },
  methods: {
    getList () {
      this.$http.get(`/sys/movie/comment/list/${this.$route.query.movieId}`).then(({ data }) => {
        if (data.code === 200) {
          this.commentList = data.data.list
          this.pageInfo = data.data
        } else {
          this.$confirm(data.msg)
        }
      })
    },
    resetForm () {

    },
    delInfo (id) {
      this.$confirm('确定删除该电影吗', '询问').then(() => {
        this.$axios.delete(`/sys/comment/delete/${id}`).then(({ data }) => {
          if (data.code === 200) {
            this.$message({
              message: '删除成功',
              type: 'success',
              onClose: () => {
                this.getList()
              }
            })
          } else {
            this.$alert('删除失败!', { type: 'error' })
          }
        })
      })
    },
    sizeChange (limit) {
      this.searchInfo.limit = limit
      this.getList()
    },
    currentChange (page) {
      this.searchInfo.page = page
      this.getList()
    }
  },
  created () {
    this.$nextTick(() => {
      this.getList()
    })
  }
}
</script>

<style scoped>

</style>
